package aop;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.lang.Nullable;

import java.lang.reflect.Method;
import java.util.Objects;

/**
 * MethodBeforeAdvice表示方法在被调用之前发出的通知
 * 该通知不能阻止方法调用的进行，除非它们抛出一个错误或异常
 */
public class CustomMethodBeforeAdvice implements MethodBeforeAdvice {
    private Log log = LogFactory.getLog(this.getClass());

    @Override
    public void before(Method method, Object[] objects, @Nullable Object o) {
        log.info("在对象" + Objects.requireNonNull(o).getClass().getName() + "调用方法" + method.getName() + "之前记录日志");
    }
}
